#include "ourhdr.h"
#include <fcntl.h>
#define BUFFSIZE 2 

int main(void) {
    int n;
    char buf[BUFFSIZE];

    // set_fl(STDOUT_FILENO, O_SYNC);

    while ((n= read(STDIN_FILENO, buf, BUFFSIZE)) > 0)
        if (write(STDOUT_FILENO, buf, n) != n)
            err_sys("write error");

    if (n < 0)
        err_sys("read error");

    exit(0);
}


void set_fl(int fd, int flags) {
    int val;
    fprintf(stderr, "flags = %d\n", flags);

    if ((val= fcntl(fd, F_GETFL, 0)) < 0)
        err_sys("fcntl F_GETFL error");
    fprintf(stderr, "val = %d\n", val);
    val |= flags;
    fprintf(stderr, "val = %d\n", val);

    int ret= fcntl(fd, F_SETFL, val);
    if (ret < 0)
        err_sys("fcntl F_SETFL error");

    fprintf(stderr, "ret= %d\n", ret);
}
